package com.ruoyi.bantong.controller;

import com.ruoyi.bantong.domain.BtUserAccountRecord;
import com.ruoyi.bantong.service.IBtUserAccountRecordService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 用户账户变动记录Controller
 * 
 * @author laohei
 * @date 2021-01-24
 */
@RestController
@RequestMapping("/bantong/userrecord")
public class BtUserAccountRecordController extends BaseController
{
    @Autowired
    private IBtUserAccountRecordService btUserAccountRecordService;

    /**
     * 查询用户账户变动记录列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(BtUserAccountRecord btUserAccountRecord)
    {
        if(StringUtils.isNull(btUserAccountRecord.getUserId())){
            btUserAccountRecord.setUserId(SecurityUtils.getBtUserId());
        }
        startPage();
        List<BtUserAccountRecord> list = btUserAccountRecordService.selectBtUserAccountRecordList(btUserAccountRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户账户变动记录列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:record:export')")
    @Log(title = "用户账户变动记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BtUserAccountRecord btUserAccountRecord)
    {
        List<BtUserAccountRecord> list = btUserAccountRecordService.selectBtUserAccountRecordList(btUserAccountRecord);
        ExcelUtil<BtUserAccountRecord> util = new ExcelUtil<BtUserAccountRecord>(BtUserAccountRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取用户账户变动记录详细信息
     */
    //@PreAuthorize("@ss.hasPermi('bantong:record:query')")
    @GetMapping(value = "/{usrId}")
    public AjaxResult getInfo(@PathVariable("usrId") Integer usrId)
    {
        return AjaxResult.success(btUserAccountRecordService.selectBtUserAccountRecordById(usrId));
    }

    /**
     * 新增用户账户变动记录
     */
    //@PreAuthorize("@ss.hasPermi('bantong:record:add')")
    @Log(title = "用户账户变动记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BtUserAccountRecord btUserAccountRecord)
    {
        return toAjax(btUserAccountRecordService.insertBtUserAccountRecord(btUserAccountRecord));
    }

    /**
     * 修改用户账户变动记录
     */
    //@PreAuthorize("@ss.hasPermi('bantong:record:edit')")
    @Log(title = "用户账户变动记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BtUserAccountRecord btUserAccountRecord)
    {
        return toAjax(btUserAccountRecordService.updateBtUserAccountRecord(btUserAccountRecord));
    }

    /**
     * 删除用户账户变动记录
     */
    //@PreAuthorize("@ss.hasPermi('bantong:record:remove')")
    @Log(title = "用户账户变动记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{usrIds}")
    public AjaxResult remove(@PathVariable Integer[] usrIds)
    {
        return toAjax(btUserAccountRecordService.deleteBtUserAccountRecordByIds(usrIds));
    }

}
